/**
 * Author: w景洋.
 * Time: 2016/8/23 0023
 */

/*底部按钮切换*/
function UserChange(x) {
    if (x == 1) {
        document.getElementById("img1").src = "images/menu-2.png"
        document.getElementById("img2").src = "images/me-1.png"
        document.getElementById("img3").src = "images/cart-1.png"
        $("#change1").find("span").addClass("bot_focus");
        $("#change2").find("span").removeClass("bot_focus");
        $("#change3").find("span").removeClass("bot_focus");
    } else if (x == 2) {
        document.getElementById("img1").src = "images/menu-1.png"
        document.getElementById("img2").src = "images/me-2.png"
        document.getElementById("img3").src = "images/cart-1.png"
        $("#change1").find("span").removeClass("bot_focus");
        $("#change2").find("span").addClass("bot_focus");
        $("#change3").find("span").removeClass("bot_focus");
    } else if (x == 3) {
        document.getElementById("img1").src = "images/menu-1.png"
        document.getElementById("img2").src = "images/me-1.png"
        document.getElementById("img3").src = "images/cart-2.png"
        $("#change1").find("span").removeClass("bot_focus");
        $("#change2").find("span").removeClass("bot_focus");
        $("#change3").find("span").addClass("bot_focus");
    } else if (x == 4) {
        document.getElementById("img1").src = "images/menu-1.png"
        document.getElementById("img2").src = "images/me-1.png"
        document.getElementById("img3").src = "images/cart-1.png"
        $("#change1").find("span").removeClass("bot_focus");
        $("#change2").find("span").removeClass("bot_focus");
        $("#change3").find("span").removeClass("bot_focus");
    }
}

//rem手机适配
new function () {
    var _self = this;
    _self.width = 640;//设置默认最大宽度
    _self.fontSize = 100;//默认字体大小
    _self.widthProportion = function () {
        var p = (document.body && document.body.clientWidth || document.getElementsByTagName("html")[0].offsetWidth) / _self.width;
        return p > 1 ? 1 : p < 0.5 ? 0.5 : p;
    };
    _self.changePage = function () {
        document.getElementsByTagName("html")[0].setAttribute("style", "font-size:" + _self.widthProportion() * _self.fontSize + "px !important");
    }
    _self.changePage();
    window.addEventListener('resize', function () {
        _self.changePage();
    }, false);
};
//输入框提示不同内容
function input_alert(html, time) {
    if (!time) {
        time = 2000;
    }
    var float_element = $(".c-float-popWrap")
    var hei = $(window).height() / 2
    var top = $(document).scrollTop() + hei - 30;
    float_element.css({"top": top + "px"})
    $(".warnMsg").html(html)
    float_element.show()
    setTimeout(function () {
        float_element.hide()
    }, time);
}
//接口同步服务器断点动画
function toastHtml(html,show) {
    var float_element = $(".c-float-popWrap")
    if(show==true){
        var hei = $(window).height() / 2
        var top = $(document).scrollTop() + hei - 30;
        float_element.css({"top": top + "px"});
        $(".warnMsg").html(html)
        float_element.show();
    }else{
        float_element.fadeOut();
    }
}
//注册页面判断
function checkPhoneIsExist() {
    return true;
}
//回顶部
function the_top() {
    window.scrollTo(0, 0);
}
//设置上传头像框高度
function setheight(id) {
    var winhei = $(window).height() - 90;
    var mywhei = $(id)
    $(id).css({"height": winhei});
}

//支付密码管理
function password(a, b, c) {
    var $input = $(a)
    $(b).on("input", function () {
        var pwd = $(this).val().trim();
        for (var i = 0, len = pwd.length; i < len; i++) {
            $input.eq("" + i + "").val(pwd[i]);
        }
        $input.each(function () {
            var index = $(this).index();
            if (index >= len) {
                $(this).val("");
            }
        });
        if (len == 6) {
            document.getElementById(c).removeAttribute("disabled");
            document.getElementById(c).style.backgroundColor = 'rgb(48, 174, 79)';
            document.getElementById(c).style.cursor = "pointer";//执行其他操作
        }
        else {
            document.getElementById(c).setAttribute("disabled", "disabled");
            document.getElementById(c).style.backgroundColor = 'rgb(94,94,94)';
            document.getElementById(c).style.cursor = "not-allowed";
        }
    });
}
//申请资金
function checkConfirm() {
    if (document.getElementById("choose").checked) {
        document.getElementById("regedit").removeAttribute("disabled");
        document.getElementById("regedit").style.backgroundColor = 'rgb(48, 174, 79)';
        document.getElementById("regedit").style.cursor = "pointer";
    } else {
        document.getElementById("regedit").setAttribute("disabled", "disabled");
        document.getElementById("regedit").style.backgroundColor = 'rgb(94,94,94)';
        document.getElementById("regedit").style.cursor = "not-allowed";
    }
}
//充值限制输入价格格式
//
function bindKeyEvent(obj) {
    obj.keyup(function () {
        var reg = $(this).val().match(/\d+\.?\d{0,2}/);
        var txt = '';
        if (reg != null) {
            txt = reg[0];
        }
        $(this).val(txt);
    }).change(function () {
        $(this).keypress();
        var v = $(this).val();
        if (/\.$/.test(v)) {
            $(this).val(v.substr(0, v.length - 1));
        }
    });
}
//点击显示隐藏
function click_show(a, b, c) {
    if ($(c).val() == 0) {
        $(a).hide();
        $(b).show();
        $(c).val(1);
    } else {
        $(a).show();
        $(b).hide();
        $(c).val(0);
    }
};
/*按钮倒计时*/
var timer;
var countdown = 60
function settime() {
    if (countdown == 0) {
        document.getElementById("getcode").removeAttribute("disabled");
        document.getElementById("getcode").value = "获取验证码";
        $("#getcode").css({"background-color": "#30AE4F"})
        clearTimeout(timer);
        countdown = 60
        return;
    }
    document.getElementById("getcode").setAttribute("disabled", true);
    document.getElementById("getcode").value = "重新发送(" + countdown + ")";
    countdown = countdown - 1;
    $("#getcode").css({"background-color": "#cccccc"})
    timer = setTimeout("settime()", 1000);
}
//模态框取消按钮函数
function dismiss() {
    $(".contain-no").click(function () {
        $(".contain-item").fadeOut();
        $(".contain-item1").fadeOut();
        $(".contain-item2").fadeOut();
    })
}
//点击显示隐藏
function click_showadr(a, b, c) {
    if ($(c).val() == 0) {
        $(a).show();
        $(b).show();
        $(c).val(1);
    } else {
        $(a).hide();
        $(b).hide();
        $(c).val(0);
    }
};
//收货地址选择所在区域功能
function  chooseDistrict(Dom,status){
    $("#chooseAddr").find('div').removeClass('active')
    $(Dom).addClass("active");
    var districtChoose = $("#districtChoose").find('.districtChoose');
    switch (status){
        case 1:
            districtChoose.hide();
            districtChoose[0].style.display = 'block';
            break;
        case 2:
            districtChoose.hide();
            districtChoose[1].style.display = 'block';
            break;
        case 3:
            districtChoose.hide();
            districtChoose[2].style.display = 'block';
            break;
        default:
            break;
    }
}
